#登录功能测试案例
# 1. 3种格式的测试数据（更新账号、密码和验证码值）
# 格式1：列表嵌套列表
data_list = [
    ["zhangsan", "zhan123", "5555", "登录成功"],
    ["zhangsan", "zhan456", "5555", "密码错误"],
    ["zhangsan", "zhan123", "6666", "验证码错误"]
]

# 格式2：元组嵌套元组
data_tuple = (
    ("lisi", "lis789", "7777", "登录成功"),
    ("", "lis789", "7777", "用户名不能为空"),
    ("lisi", "", "7777", "密码不能为空")
)

# 格式3：列表嵌套字典
data_dict = [
    {"user": "wangwu", "pwd": "wan000", "code": "9999", "expect": "登录成功"},
    {"user": "wangwu", "pwd": "wan000", "code": "", "expect": "验证码不能为空"}
]


# 2. 模拟登录验证函数（匹配新的正确值）
def check_login(user, pwd, code):
    """简单验证逻辑，返回实际结果"""
    # 预设正确值（与测试数据对应）
    correct = {"zhangsan": "zhan123", "lisi": "lis789", "wangwu": "wan000"}
    valid_codes = ["5555", "7777", "9999"]  # 有效验证码

    # 非空校验
    if not user:
        return "用户名不能为空"
    if not pwd:
        return "密码不能为空"
    if not code:
        return "验证码不能为空"

    # 账号密码验证
    if user not in correct:
        return "用户名错误"
    if correct[user] != pwd:
        return "密码错误"
    if code not in valid_codes:
        return "验证码错误"

    return "登录成功"


# 3. 执行测试并打印结果
def run_test(data, data_type):
    print(f"\n--- {data_type}格式测试 ---")
    for i, case in enumerate(data, 1):
        # 提取数据（根据格式处理）
        if isinstance(case, dict):
            user = case["user"]
            pwd = case["pwd"]
            code = case.get("code", "")
            expect = case["expect"]
        else:
            user, pwd, code, expect = case

        # 执行验证
        actual = check_login(user, pwd, code)
        result = "通过" if actual == expect else "失败"

        # 打印结果
        print(f"用例{i}：用户名={user} 密码={pwd} 验证码={code} | "
              f"期望={expect} 实际={actual} | {result}")


# 4. 运行所有测试
run_test(data_list, "列表")
run_test(data_tuple, "元组")
run_test(data_dict, "字典")